package #(projectPackage ??).service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import #(projectPackage ??).model.#(claUpName ??);
import #(projectPackage ??).service.#(claUpName ??)Service;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;



/**
 * #(table.remarks ??)Service
 */
public class #(claUpName ??)ServiceImpl implements #(claUpName ??)Service{

	private static final Logger logger = LoggerFactory.getLogger(#(claUpName ??)ServiceImpl.class);

	// ---------------   系统自动生成 -请勿改动  以上区域为自行添加   -----------------
	
	//@Cacheable(cacheNames= ConstantsUtils.CACHE_NAME_OF_#(claUpName ??),key = "#{id}")
	@Override
	public #(claUpName ??) getById(Integer id){
		logger.info("查询#(table.remarks ??)id{}", id);
		return #(claUpName ??).dao.findById(id);
	}

	//@CacheEvict(cacheNames=ConstantsUtils.CACHE_NAME_OF_#(claUpName ??), allEntries = true)
	@Override
	public boolean save(#(claUpName ??) #(claLowName ??)) {
		logger.info("新增#(table.remarks ??)id{}", #(claLowName ??));
		return #(claLowName ??).save();
	}

	@Override
	public boolean delete(Integer id) {
		logger.info("删除#(table.remarks ??)id{}", id);
		return Db.update("delete from #(table.name ??) where id=?", id) == 1;
	}

	//@CacheEvict(cacheNames=ConstantsUtils.CACHE_NAME_OF_#(claUpName ??), allEntries = true)
	@Override
	public boolean update(#(claUpName ??) #(claLowName ??)) {
		logger.info("更新#(table.remarks ??)id{}", #(claLowName ??));
		return #(claLowName ??).update();
	}
	
	//列表
	@Override
	public List<Record> list(Map<String,String> param) {
		logger.info("获取列表参数{}", param);
		return Db.find(Db.getSqlPara("#(claLowName ??).list", param));
	}
	
	//分页
	@Override
	public Page<Record> pageList(int pageNum, int pageSize,Map<String, String> paraMap,String sort,String order) {
		logger.info("分页参数{}", paraMap);
		paraMap.remove("pageNum");
		paraMap.remove("pageSize");
		paraMap.remove("sort");
		paraMap.remove("order");
		SqlPara para = Db.getSqlPara("#(claLowName ??).pageList", Kv.by("params", paraMap).set("sort", sort).set("order", order));
		return Db.paginate(pageNum, pageSize, para);
	}
	
	//分页1
	@Override
	public Page<Record> pageList1(int pageNum, int pageSize,Map<String, String> paraMap,String sort,String order) {
		logger.info("分页参数{}", paraMap);
		paraMap.remove("page");
		paraMap.remove("limit");
		paraMap.remove("sort");
		paraMap.remove("order");
		Kv kv = Kv.by("id=", paraMap.get("id"));
		SqlPara para = Db.getSqlPara("#(claLowName ??).pageList1", Kv.by("params", kv).set("sort", sort).set("order", order));
		return Db.paginate(pageNum, pageSize, para);
	}
	
	// ---------------   系统自动生成 -请勿改动  以下区域为自行添加   -----------------

}